package com.hefu.virtuallife.ui.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.hefu.virtuallife.R;
import com.hefu.virtuallife.bean.SmartHomeBean;
import com.hefu.virtuallife.utils.SmartDataUtils;

import java.util.HashMap;
import java.util.List;

/**
 * Created by pc on 2018/7/29.
 */

public class RoomEqAdapter extends BaseAdapter {
    private LayoutInflater inflater = null;
    private View view;
    private List<String> roomList;
    private Context mContext;
    private HashMap<String, List<String>> eq_map;

    public RoomEqAdapter(Context context, List<String> room_list, HashMap<String, List<String>> map){
        this.roomList = room_list;
        this.eq_map = map;
        mContext = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return roomList.size();
    }

    @Override
    public Object getItem(int position) {
        return roomList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        view = inflater.inflate(R.layout.smart_home_item, null);

        TextView iv_room = (TextView)view.findViewById(R.id.tv_room);
        TableLayout tl_room = (TableLayout)view.findViewById(R.id.tl_eqs);

        iv_room.setText(roomList.get(position));

        TableRow row = new TableRow(mContext);

        String room = roomList.get(position);
        List<String> list = eq_map.get(room);
        int num = 0;
        for (String eq : list){
            if (num == 7){
                break;
            }
            TextView tv = new TextView(mContext);
            if (num > 0){
                tv.setPadding(30, 0, 0,0);
            }
            tv.setText(eq);
            Drawable drawable = mContext.getResources().getDrawable(SmartDataUtils.getResByName(eq));
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            tv.setCompoundDrawables(null, drawable, null, null);
            row.addView(tv);
            num++;
        }
        tl_room.addView(row);
        return view;
    }
}
